home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / controls / HTML.as < prev    next >
Encoding:
Text File  |  2009-02-12  |  14.7 KB  |  514 lines

  1. package mx.controls
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.HTMLUncaughtScriptExceptionEvent;
  5.    import flash.events.MouseEvent;
  6.    import flash.html.HTMLHistoryItem;
  7.    import flash.html.HTMLHost;
  8.    import flash.html.HTMLLoader;
  9.    import flash.net.URLRequest;
  10.    import flash.system.ApplicationDomain;
  11.    import mx.controls.listClasses.BaseListData;
  12.    import mx.controls.listClasses.IDropInListItemRenderer;
  13.    import mx.controls.listClasses.IListItemRenderer;
  14.    import mx.core.ClassFactory;
  15.    import mx.core.EdgeMetrics;
  16.    import mx.core.FlexHTMLLoader;
  17.    import mx.core.IDataRenderer;
  18.    import mx.core.IFactory;
  19.    import mx.core.ScrollControlBase;
  20.    import mx.core.ScrollPolicy;
  21.    import mx.core.mx_internal;
  22.    import mx.events.FlexEvent;
  23.    import mx.managers.IFocusManagerComponent;
  24.    
  25.    use namespace mx_internal;
  26.    
  27.    public class HTML extends ScrollControlBase implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer, IFocusManagerComponent
  28.    {
  29.       mx_internal static const VERSION:String = "3.0.0.0";
  30.       
  31.       private static const MAX_HTML_WIDTH:Number = 2880;
  32.       
  33.       private static const MAX_HTML_HEIGHT:Number = 2880;
  34.       
  35.       private var _data:Object;
  36.       
  37.       private var _userAgent:String;
  38.       
  39.       private var _htmlLoaderFactory:IFactory;
  40.       
  41.       private var _location:String;
  42.       
  43.       private var _runtimeApplicationDomain:ApplicationDomain;
  44.       
  45.       private var htmlTextChanged:Boolean = false;
  46.       
  47.       public var htmlLoader:HTMLLoader;
  48.       
  49.       private var _paintsDefaultBackground:Boolean;
  50.       
  51.       private var locationChanged:Boolean = false;
  52.       
  53.       private var htmlHostChanged:Boolean = false;
  54.       
  55.       private var _listData:BaseListData;
  56.       
  57.       private var _htmlText:String;
  58.       
  59.       private var _htmlHost:HTMLHost;
  60.       
  61.       private var paintsDefaultBackgroundChanged:Boolean = false;
  62.       
  63.       private var userAgentChanged:Boolean = false;
  64.       
  65.       private var runtimeApplicationDomainChanged:Boolean = false;
  66.       
  67.       private var textSet:Boolean;
  68.       
  69.       public function HTML()
  70.       {
  71.          _htmlLoaderFactory = new ClassFactory(FlexHTMLLoader);
  72.          super();
  73.          mx_internal::_horizontalScrollPolicy = ScrollPolicy.AUTO;
  74.          mx_internal::_verticalScrollPolicy = ScrollPolicy.AUTO;
  75.          tabEnabled = false;
  76.          tabChildren = true;
  77.       }
  78.       
  79.       public static function get pdfCapability() : int
  80.       {
  81.          return HTMLLoader.pdfCapability;
  82.       }
  83.       
  84.       public function get contentHeight() : Number
  85.       {
  86.          if(!htmlLoader)
  87.          {
  88.             return 0;
  89.          }
  90.          return htmlLoader.contentHeight;
  91.       }
  92.       
  93.       public function get userAgent() : String
  94.       {
  95.          return _userAgent;
  96.       }
  97.       
  98.       public function set userAgent(param1:String) : void
  99.       {
  100.          _userAgent = param1;
  101.          userAgentChanged = true;
  102.          invalidateProperties();
  103.       }
  104.       
  105.       public function get loaded() : Boolean
  106.       {
  107.          if(!htmlLoader || locationChanged || htmlTextChanged)
  108.          {
  109.             return false;
  110.          }
  111.          return htmlLoader.loaded;
  112.       }
  113.       
  114.       public function cancelLoad() : void
  115.       {
  116.          if(htmlLoader)
  117.          {
  118.             htmlLoader.cancelLoad();
  119.          }
  120.       }
  121.       
  122.       private function htmlLoader_htmlRenderHandler(param1:Event) : void
  123.       {
  124.          dispatchEvent(param1);
  125.          adjustScrollBars();
  126.       }
  127.       
  128.       [Bindable("htmlLoaderFactoryChanged")]
  129.       public function get htmlLoaderFactory() : IFactory
  130.       {
  131.          return _htmlLoaderFactory;
  132.       }
  133.       
  134.       public function historyForward() : void
  135.       {
  136.          if(htmlLoader)
  137.          {
  138.             htmlLoader.historyForward();
  139.          }
  140.       }
  141.       
  142.       public function set htmlLoaderFactory(param1:IFactory) : void
  143.       {
  144.          _htmlLoaderFactory = param1;
  145.          dispatchEvent(new Event("htmlLoaderFactoryChanged"));
  146.       }
  147.       
  148.       public function get historyLength() : int
  149.       {
  150.          if(!htmlLoader)
  151.          {
  152.             return 0;
  153.          }
  154.          return htmlLoader.historyLength;
  155.       }
  156.       
  157.       public function reload() : void
  158.       {
  159.          if(htmlLoader)
  160.          {
  161.             htmlLoader.reload();
  162.          }
  163.       }
  164.       
  165.       override protected function createChildren() : void
  166.       {
  167.          super.createChildren();
  168.          if(!htmlLoader)
  169.          {
  170.             htmlLoader = htmlLoaderFactory.newInstance();
  171.             htmlLoader.addEventListener(Event.HTML_DOM_INITIALIZE,htmlLoader_domInitialize);
  172.             htmlLoader.addEventListener(Event.COMPLETE,htmlLoader_completeHandler);
  173.             htmlLoader.addEventListener(Event.HTML_RENDER,htmlLoader_htmlRenderHandler);
  174.             htmlLoader.addEventListener(Event.LOCATION_CHANGE,htmlLoader_locationChangeHandler);
  175.             htmlLoader.addEventListener(Event.HTML_BOUNDS_CHANGE,htmlLoader_htmlBoundsChangeHandler);
  176.             htmlLoader.addEventListener(Event.SCROLL,htmlLoader_scrollHandler);
  177.             htmlLoader.addEventListener(HTMLUncaughtScriptExceptionEvent.UNCAUGHT_SCRIPT_EXCEPTION,htmlLoader_uncaughtScriptExceptionHandler);
  178.             addChild(htmlLoader);
  179.          }
  180.       }
  181.       
  182.       public function historyGo(param1:int) : void
  183.       {
  184.          if(htmlLoader)
  185.          {
  186.             htmlLoader.historyGo(param1);
  187.          }
  188.       }
  189.       
  190.       private function htmlLoader_domInitialize(param1:Event) : void
  191.       {
  192.          dispatchEvent(param1);
  193.       }
  194.       
  195.       private function adjustScrollBars() : void
  196.       {
  197.          setScrollBarProperties(htmlLoader.contentWidth,htmlLoader.width,htmlLoader.contentHeight,htmlLoader.height);
  198.          if(verticalScrollBar)
  199.          {
  200.             verticalScrollBar.lineScrollSize = 20;
  201.          }
  202.          if(horizontalScrollBar)
  203.          {
  204.             horizontalScrollBar.lineScrollSize = 20;
  205.          }
  206.       }
  207.       
  208.       [Bindable("dataChange")]
  209.       public function get data() : Object
  210.       {
  211.          return _data;
  212.       }
  213.       
  214.       [Bindable("locationChange")]
  215.       public function get location() : String
  216.       {
  217.          return _location;
  218.       }
  219.       
  220.       private function htmlLoader_completeHandler(param1:Event) : void
  221.       {
  222.          invalidateSize();
  223.          dispatchEvent(param1);
  224.       }
  225.       
  226.       public function set historyPosition(param1:int) : void
  227.       {
  228.          if(htmlLoader)
  229.          {
  230.             htmlLoader.historyPosition = param1;
  231.          }
  232.       }
  233.       
  234.       public function getHistoryAt(param1:int) : HTMLHistoryItem
  235.       {
  236.          if(!htmlLoader)
  237.          {
  238.             return null;
  239.          }
  240.          return htmlLoader.getHistoryAt(param1);
  241.       }
  242.       
  243.       public function get runtimeApplicationDomain() : ApplicationDomain
  244.       {
  245.          return _runtimeApplicationDomain;
  246.       }
  247.       
  248.       override protected function scrollHandler(param1:Event) : void
  249.       {
  250.          super.scrollHandler(param1);
  251.          htmlLoader.scrollH = horizontalScrollPosition;
  252.          htmlLoader.scrollV = verticalScrollPosition;
  253.       }
  254.       
  255.       public function historyBack() : void
  256.       {
  257.          if(htmlLoader)
  258.          {
  259.             htmlLoader.historyBack();
  260.          }
  261.       }
  262.       
  263.       override protected function commitProperties() : void
  264.       {
  265.          super.commitProperties();
  266.          if(htmlHostChanged)
  267.          {
  268.             htmlLoader.htmlHost = _htmlHost;
  269.             htmlHostChanged = false;
  270.          }
  271.          if(paintsDefaultBackgroundChanged)
  272.          {
  273.             htmlLoader.paintsDefaultBackground = _paintsDefaultBackground;
  274.             paintsDefaultBackgroundChanged = false;
  275.          }
  276.          if(runtimeApplicationDomainChanged)
  277.          {
  278.             htmlLoader.runtimeApplicationDomain = _runtimeApplicationDomain;
  279.             runtimeApplicationDomainChanged = false;
  280.          }
  281.          if(userAgentChanged)
  282.          {
  283.             htmlLoader.userAgent = _userAgent;
  284.             userAgentChanged = false;
  285.          }
  286.          if(locationChanged)
  287.          {
  288.             htmlLoader.load(new URLRequest(_location));
  289.             locationChanged = false;
  290.          }
  291.          if(htmlTextChanged)
  292.          {
  293.             htmlLoader.loadString(_htmlText);
  294.             htmlTextChanged = false;
  295.          }
  296.       }
  297.       
  298.       public function get contentWidth() : Number
  299.       {
  300.          if(!htmlLoader)
  301.          {
  302.             return 0;
  303.          }
  304.          return htmlLoader.contentWidth;
  305.       }
  306.       
  307.       public function get domWindow() : Object
  308.       {
  309.          if(!htmlLoader)
  310.          {
  311.             return null;
  312.          }
  313.          return htmlLoader.window;
  314.       }
  315.       
  316.       override protected function mouseWheelHandler(param1:MouseEvent) : void
  317.       {
  318.          if(param1.target != this)
  319.          {
  320.             return;
  321.          }
  322.          param1.delta *= 6;
  323.          super.mouseWheelHandler(param1);
  324.       }
  325.       
  326.       override public function set verticalScrollPosition(param1:Number) : void
  327.       {
  328.          param1 = Math.max(param1,0);
  329.          if(Boolean(htmlLoader) && htmlLoader.contentHeight > htmlLoader.height)
  330.          {
  331.             param1 = Math.min(param1,htmlLoader.contentHeight - htmlLoader.height);
  332.          }
  333.          super.verticalScrollPosition = param1;
  334.          if(htmlLoader)
  335.          {
  336.             htmlLoader.scrollV = param1;
  337.          }
  338.          else
  339.          {
  340.             invalidateProperties();
  341.          }
  342.       }
  343.       
  344.       public function set data(param1:Object) : void
  345.       {
  346.          var _loc2_:* = undefined;
  347.          _data = param1;
  348.          if(_listData)
  349.          {
  350.             _loc2_ = _listData.label;
  351.          }
  352.          else if(_data != null)
  353.          {
  354.             if(_data is String)
  355.             {
  356.                _loc2_ = String(_data);
  357.             }
  358.             else
  359.             {
  360.                _loc2_ = _data.toString();
  361.             }
  362.          }
  363.          if(_loc2_ !== undefined && !textSet)
  364.          {
  365.             htmlText = _loc2_;
  366.             textSet = false;
  367.          }
  368.          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  369.       }
  370.       
  371.       private function htmlLoader_scrollHandler(param1:Event) : void
  372.       {
  373.          horizontalScrollPosition = htmlLoader.scrollH;
  374.          verticalScrollPosition = htmlLoader.scrollV;
  375.       }
  376.       
  377.       public function get historyPosition() : int
  378.       {
  379.          if(!htmlLoader)
  380.          {
  381.             return 0;
  382.          }
  383.          return htmlLoader.historyPosition;
  384.       }
  385.       
  386.       override protected function measure() : void
  387.       {
  388.          super.measure();
  389.          var _loc1_:EdgeMetrics = viewMetrics;
  390.          _loc1_.left += getStyle("paddingLeft");
  391.          _loc1_.top += getStyle("paddingTop");
  392.          _loc1_.right += getStyle("paddingRight");
  393.          _loc1_.bottom += getStyle("paddingBottom");
  394.          measuredWidth = Math.min(htmlLoader.contentWidth + _loc1_.left + _loc1_.right,MAX_HTML_WIDTH);
  395.          measuredHeight = Math.min(htmlLoader.contentHeight + _loc1_.top + _loc1_.bottom,MAX_HTML_HEIGHT);
  396.       }
  397.       
  398.       public function set listData(param1:BaseListData) : void
  399.       {
  400.          _listData = param1;
  401.       }
  402.       
  403.       private function htmlLoader_uncaughtScriptExceptionHandler(param1:HTMLUncaughtScriptExceptionEvent) : void
  404.       {
  405.          var _loc2_:Event = param1.clone();
  406.          dispatchEvent(_loc2_);
  407.          if(_loc2_.isDefaultPrevented())
  408.          {
  409.             param1.preventDefault();
  410.          }
  411.       }
  412.       
  413.       private function htmlLoader_locationChangeHandler(param1:Event) : void
  414.       {
  415.          var _loc2_:* = _location != htmlLoader.location;
  416.          _location = htmlLoader.location;
  417.          if(_loc2_)
  418.          {
  419.             dispatchEvent(param1);
  420.          }
  421.       }
  422.       
  423.       public function set htmlHost(param1:HTMLHost) : void
  424.       {
  425.          _htmlHost = param1;
  426.          htmlHostChanged = true;
  427.          invalidateProperties();
  428.       }
  429.       
  430.       [Bindable("dataChange")]
  431.       public function get listData() : BaseListData
  432.       {
  433.          return _listData;
  434.       }
  435.       
  436.       public function set htmlText(param1:String) : void
  437.       {
  438.          _htmlText = param1;
  439.          htmlTextChanged = true;
  440.          _location = null;
  441.          locationChanged = false;
  442.          invalidateProperties();
  443.          invalidateSize();
  444.          invalidateDisplayList();
  445.          dispatchEvent(new Event("htmlTextChanged"));
  446.       }
  447.       
  448.       public function set location(param1:String) : void
  449.       {
  450.          _location = param1;
  451.          locationChanged = true;
  452.          _htmlText = null;
  453.          htmlTextChanged = false;
  454.          invalidateProperties();
  455.          invalidateSize();
  456.          invalidateDisplayList();
  457.          dispatchEvent(new Event("locationChange"));
  458.       }
  459.       
  460.       public function get htmlHost() : HTMLHost
  461.       {
  462.          return _htmlHost;
  463.       }
  464.       
  465.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  466.       {
  467.          super.updateDisplayList(param1,param2);
  468.          var _loc3_:EdgeMetrics = viewMetrics;
  469.          _loc3_.left += getStyle("paddingLeft");
  470.          _loc3_.top += getStyle("paddingTop");
  471.          _loc3_.right += getStyle("paddingRight");
  472.          _loc3_.bottom += getStyle("paddingBottom");
  473.          htmlLoader.x = _loc3_.left;
  474.          htmlLoader.y = _loc3_.top;
  475.          var _loc4_:Number = Math.max(param1 - _loc3_.left - _loc3_.right,1);
  476.          var _loc5_:Number = Math.max(param2 - _loc3_.top - _loc3_.bottom,1);
  477.          htmlLoader.width = _loc4_;
  478.          htmlLoader.height = _loc5_;
  479.       }
  480.       
  481.       [Bindable("htmlTextChanged")]
  482.       public function get htmlText() : String
  483.       {
  484.          return _htmlText;
  485.       }
  486.       
  487.       private function htmlLoader_htmlBoundsChangeHandler(param1:Event) : void
  488.       {
  489.          invalidateSize();
  490.          adjustScrollBars();
  491.       }
  492.       
  493.       public function get paintsDefaultBackground() : Boolean
  494.       {
  495.          return _paintsDefaultBackground;
  496.       }
  497.       
  498.       public function set paintsDefaultBackground(param1:Boolean) : void
  499.       {
  500.          _paintsDefaultBackground = param1;
  501.          paintsDefaultBackgroundChanged = true;
  502.          invalidateProperties();
  503.       }
  504.       
  505.       public function set runtimeApplicationDomain(param1:ApplicationDomain) : void
  506.       {
  507.          _runtimeApplicationDomain = param1;
  508.          runtimeApplicationDomainChanged = true;
  509.          invalidateProperties();
  510.       }
  511.    }
  512. }
  513.  
  514.